#include <iostream>
#include <unistd.h>
#include <pthread.h>
#include <string>
#include <cstdio>
using namespace std;
pthread_mutex_t mux = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP;
void *fun(void *p)
{
    string name = static_cast<const char *>(p);
    int n = 10;
    while (n--)
    {
        sleep(1);
        pthread_mutex_lock(&mux);
        cout << name << endl;
        pthread_mutex_unlock(&mux);
    }
    return nullptr;
}
int main()
{
    pthread_t tids[10];
    for (int i = 0; i < 10; i++)
    {
        char buf[128];
        snprintf(buf, sizeof(buf), "thread-%d", i);
        pthread_create(&tids[i], nullptr, fun, (void *)buf);
    }
    for (int i = 0; i < 10; i++)
        pthread_join(tids[i], nullptr);
    return 0;
}